<?php
class IndexAction extends Action {
    public function index(){
		$this->_nav();
		$Links = M('Links');
		$Activity = M('Activity');
		$list = $Links->select();
		$at = $Activity->select();
		$this->assign('friendlinks',$list);
		$this->assign('activity',$at);
		$this->display();
    }
	public function login(){
		if(IS_POST){
			$param = $this->_post();
			if($param['account'] && $param['password']){
				$Account= M('Account');
				$v = $Account->where(array('account'=>trim($param['account']),'password'=>MD5(trim($param['password']))))->find();
				if(!$v){
					$this->error('账户和密码不匹配');
				}else{
					session('uid',$v['uid']);
					$this->redirect('Admin/index');
				}
			}else if(!$param['account']){
				$this->error('请输入账户');
			}else if(!$param['account']){
				$this->error('请输入密码');
			}else{
				$this->error('账户和密码不匹配');
			}
		}else{
			session(null);
			$this->display();
		}
	}
	public function cases(){
		$Img = M('Img');
		$param = $this->_param();
		if($param['id']){
			$where['img_group_id'] = $param['id'];
			$list = $Img->where($where)->select();

		}else{
			$list = $Img->select();
		}
		
		foreach($list as $k => $v){
			if($v['img_url']){
				$list[$k]['img_url'] =  'http://'.$_SERVER ['HTTP_HOST'].__ROOT__.'/'.$v['img_url'];
				$list[$k]['title'] =  $v['img_title'];
			}
		}
		$this->_nav();
		$this->assign('list',$list);
		$this->display();
    }
	public function suites(){
		$Suites = M('Suites');
		$list = $Suites->where()->select();
		$results = array();
		
		$this->_nav();
		$this->assign('list',$list);
		$this->display();
	}
	public function about(){
		$Config = M('Config');
		$list = $Config->where("name='about'")->select();
		$results = array();
		foreach($list as $v){
			if($v['value']) $results[$v['name']] = $v['value'] ;
		}
		$this->_nav();
		$this->assign('list',$results);
		$this->display();
	}
	public function notice(){
		$this->_nav();
		$this->display();
	}
	//联系我们
	public function contact(){
		$Config = M('Config');
		$list = $Config->where()->select();
		$results = array();
		foreach($list as $v){
			if($v['value']) $results[$v['name']] = $v['value'] ;
		}
		$this->_nav();
		$this->assign('list',$results);
		$this->display();
	}
	protected function _nav(){
		$Group = M('Group');
		$lists = $Group->where('status = 1')->order('id')->select();
		$Config = M('Config');
		$list = $Config->select();
		$results = array();
		foreach($list as $v){
			if($v['value']) $results[$v['name']] = $v['value'] ;
		}
		$this->assign('config',$results);
		$this->assign('nav',$lists);
	}
	protected function _config(){
		$Config = M('Config');
		$list = $Config->select();
		$results = array();
		foreach($list as $v){
			if($v['value']) $results[$v['name']] = $v['value'] ;
		}
		$this->_nav();
		$this->assign('config',$results);
	}
}